package org.mspring.platform.api.rss.writers.defaults;

import java.util.Iterator;
import java.util.List;

import org.mspring.platform.api.rss.elements.CategorizedElement;
import org.mspring.platform.api.rss.elements.Category;
import org.mspring.platform.api.rss.elements.Channel;
import org.mspring.platform.api.rss.elements.Item;
import org.mspring.platform.api.rss.writers.GenericRSSWriter;

import electric.xml.Element;

@SuppressWarnings({ "rawtypes" })
public class RSS200 extends RSS092 {
    protected void addExtrasToChannel(Element element, Channel channel) {
        addCategories(element, channel);
        GenericRSSWriter.addElement(element, "copyright", channel.getCopyright());
        GenericRSSWriter.addElement(element, "language", channel.getLanguage());
        GenericRSSWriter.addElement(element, "managingEditor", channel.getManagingEditor());
        GenericRSSWriter.addElement(element, "generator", channel.getGenerator());
    }

    protected String getVersion() {
        return "2.0";
    }

    protected String getDocs() {
        return "http://backend.userland.com/rss";
    }

    protected void addCategories(Element element, CategorizedElement categorizedElement) {
        List localList = categorizedElement.getCategories();
        if (localList != null) {
            Iterator localIterator = localList.iterator();
            while (localIterator.hasNext()) {
                Category localCategory = (Category) localIterator.next();
                Element localElement = element.addElement("category");
                localElement.setText(localCategory.getText());
                String str = localCategory.getDomain();
                if (str == null)
                    continue;
                localElement.setAttribute("domain", str);
            }
        }
    }

    protected void addExtrasToItem(Element element, Item item) {
        addCategories(element, item);
    }
}